import msgpack
 
# 将Python对象序列化为MessagePack格式
python_object = {'key': 'value', 'array': [1, 2, 3]}
packed_data = msgpack.packb(python_object, use_bin_type=True)
print(packed_data)
 
# 将MessagePack格式数据反序列化为Python对象
unpacked_data = msgpack.unpackb(packed_data)
print(packed_data)